#ifndef __I2C_H 
#define __I2C_H 

#define I2C_CR		               	0x00
#define I2C_SR 		               	0x04
#define I2C_CDR		              	0x08
#define I2C_DR                   	0x0C
#define I2C_SAR		              	0x10
#define I2C_TGSR                  	0x14
#define I2C_BMR                   	0x18 
#define I2C_SMCR                   	0x1C
#define I2C_MAXTR                  	0x20
#define I2C_MINTR                  	0x24
#define I2C_METR                   	0x28
#define I2C_SETR                  	0x2C
#define I2C_REVISION               	0x30
#define I2C_FEATURE                	0x34


// --------------------------------------------------------------------
// config
// --------------------------------------------------------------------
#define I2C_Default_FREQ        	(45 * 1000)
#define I2C_MAX_FREQ                (400 * 1000)
#define WRITE_TIME_OUT				100000		// 100000
#define READ_TIME_OUT				100000		// 100000

#define I2C_GSR_Value		0x03		// general value of gsr & tsr
#define I2C_TSR_Value		0x01

#define divRoundUp(n,s)     ((n+s-1)/(s))


/*  -------------------------------------------------------------------------------
 *   API
 *  -------------------------------------------------------------------------------
 */
extern int I2C_SetSCLout(unsigned int base_addr, unsigned int i_SCLout);
extern void i2c_init(void);
extern int i2c_write(unsigned char slave_addr, unsigned char* buf, unsigned int length, int stop_en);
extern int i2c_read(unsigned char slave_addr, unsigned char* buf, unsigned int length);


#endif // __SERIAL_H 
